#ifndef FUNCTION_H
#define FUNCTION_H

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <signal.h>

#define MAX_MICRO_SEC 1000000

/*!
	@function next_interval
	@abstract Computes the next time interval
	@param next_time is the current time add to the interval
	@param current_time is the current time
	@param interval is the interval to add in micro-secondes
*/
void next_interval(struct timeval *next_time, const struct timeval *current_time, long interval);

/*!
	@function timeval_comparison
	@abstract Comparison between timeval structures
	@param time_1 is the first time to compare
	@param time_2 is the second time to compare
	@return 1 if time_1 is more recent than time_2, 2 if time_2 is more recent, 0 otherwise
*/
int timeval_comparison(const struct timeval *time_1, const struct timeval *time_2);

/*!
	@function interval_definition
	@abstract Computes the times to launch tests for the experiment
	@param interval_array is the array of timeval's pointers
	@param interval is the interval in micro-seconds between the tests
	@param number_of_tests is the number of tests
*/
void interval_definition(struct timeval **interval_array, const struct timeval *start_time, long interval, int number_of_tests);

/*!
	@function active_launch
	@abstract Active waiting to launch the tests
	@param interval is the interval in micro-seconds between the tests
	@param number_of_tests is the number of tests
	@return 1 if success
*/
int active_launch(long interval, int number_of_tests);

/*!
	@function clean_interval_array
	@abstract clean the interval_array 
	@param interval_array is the array of timeval's pointers
	@param number_of_tests is the number of square of interval_array
*/
void clean_interval_array(struct timeval **interval_array, int number_of_tests);

#endif